/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package spaceinvaders;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;

/**
 *
 * @author jorge
 */
public class JVentana extends JFrame implements KeyListener
{

    private JSpace jspace;
    private Space space;

    public JVentana()
    {
        super("Space Inveders");
        super.setSize(735, 650);
        super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //super.setBackground(Color.black);
        super.addKeyListener(this);

        this.space = new Space();
        this.jspace = new JSpace(space);


        super.add(this.jspace);

        super.setVisible(true);
    }

    public void keyTyped(KeyEvent e)
    {
    }

    public void keyPressed(KeyEvent e)
    {
        if (e.getKeyCode() == e.VK_LEFT)
        {
            this.space.setMoverTerricola(-1);
        }
        else if (e.getKeyCode() == e.VK_RIGHT)
        {
            this.space.setMoverTerricola(1);
        }
        else if(e.getKeyCode() == e.VK_SPACE)
        {
            this.space.disparo();
        }
    }

    public void keyReleased(KeyEvent e)
    {
        if (e.getKeyCode() == e.VK_LEFT)
        {
            this.space.setMoverTerricola(0);
        }
        else if(e.getKeyCode() == e.VK_RIGHT)
        {
            this.space.setMoverTerricola(0);
        }

    }
}
